package springboot.kafka.thread;

import java.util.concurrent.CountDownLatch;

/**
 * 出现异常门闩减一
 */
public class TimeCount {

    public static void main(String[] args) {
        Long startTime = System.currentTimeMillis();
        CountDownLatch countDownLatch = new CountDownLatch(500);
        for (int i = 1; i <= 500; i++) {
            new Thread(() -> {
                System.out.println("执行行数：" + Thread.currentThread().getName());
                try {
                    Thread.sleep(3000L);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    countDownLatch.countDown();
                }
            }).start();
        }
        try {
            countDownLatch.await();  //一定要等到countDown()方法执行完毕后才使用
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("执行总时间:" + (System.currentTimeMillis() - startTime));
    }

}
